package com.njtoyo.taxi.admin.library.common.util;

import cn.hutool.core.date.DateUtil;
import com.njtoyo.taxi.admin.rest.presenter.common.ChartCyclesTimeListPresenter;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ChartUtil {

    /**
     * 根据起止时间按天生成时间间隔
     */
    public static List<ChartCyclesTimeListPresenter> getCyclesByCustomizeDaily(Date startTime, Date endTime) {
        List<ChartCyclesTimeListPresenter> res = new ArrayList<>();

        for (Date st = startTime; st.equals(endTime) || st.before(endTime); st = DateUtil.offsetDay(st, 1)) {
            ChartCyclesTimeListPresenter item = new ChartCyclesTimeListPresenter();
            item.setStartTime(DateUtil.beginOfDay(st));
            item.setEndTime(DateUtil.endOfDay(st));

            res.add(item);
        }

        return res;
    }
}

